<?php
defined( '_JEXEC' ) or die( 'Restricted access' );

jimport( 'joomla.application.component.view');

class SimplelistingViewListings extends JView
{


	function display($tpl = null)
	{
            global $mainframe, $context;
            $model =& $this->getModel();

            $document = & JFactory::getDocument();
            $params = &JComponentHelper::getParams( 'com_simplelisting');

            $uri	=& JFactory::getURI();
            $pathway =& $mainframe->getPathWay();
            $backlink = JRoute::_('index.php?option='.$option);

            /* Parameters */
            $currency         = $params->get('currency_symbol', '');
            $listtitle        = $params->get('listtitle', '');
            $priceLabel       = $params->get('price_label', '');
            $categoryLabel    = $params->get('category_label', '');
            $addressLabel     = $params->get('address_label', '');
            $typeLabel        = $params->get('type_label', '');
            $countryLabel     = $params->get('country_label', '');
            $extrasLabel      = $params->get('extras_label', '');
            $layoutLabel      = $params->get('layout_label', '');
            $facilitiesLabel  = $params->get('facilities_label', '');
            $postedLabel      = $params->get('posted_label', '');
            $select_theme     = $params->get('select_theme', '');
            $show_price_admin = $params->get('show_price_admin', '');
            $currencyformat   = $params->get('FormatPrice');


            $items	 =& $this->get( 'Data');
            $total       =& $this->get( 'Total');
            $pagination  =& $this->get( 'Pagination' );

            $db          =& JFactory::getDBO();

            $query = 'SELECT a.* FROM #__simplelisting_categories as a WHERE a.published=1 ORDER BY a.ordering ASC';
            $db->setQuery( $query );
            $fcategory_id = array();
            $fcategory_id[]   = JHTML::_('select.option', '0', JText::_( 'SELECT_CATEGORY' ), 'id', 'name' );
            $fcategory_id = array_merge( $fcategory_id, $db->loadObjectList() );
            $lists['fcategory_id']   = JHTML::_('select.genericlist', $fcategory_id, 'fcategory_id', 'class="inputbox" size="1"','id', 'name' );

            $query = 'SELECT a.* FROM #__simplelisting_types as a WHERE a.published=1 ORDER BY a.ordering ASC';
            $db->setQuery( $query );
            $ftype_id = array();
            $ftype_id[]   = JHTML::_('select.option', '0', JText::_( 'SELECT_TYPE' ), 'id', 'name' );
            $ftype_id = array_merge( $ftype_id, $db->loadObjectList() );
            $lists['ftype_id']   = JHTML::_('select.genericlist', $ftype_id, 'ftype_id', 'class="inputbox" size="1"','id', 'name' );

            $query = 'SELECT a.* FROM #__simplelisting_countries as a ORDER BY a.ordering ASC';
            $db->setQuery( $query );
            $fcountry_id = array();
            $fcountry_id[]   = JHTML::_('select.option', '0', JText::_( 'SELECT_COUNTRY' ), 'id', 'name' );
            $fcountry_id = array_merge( $fcountry_id, $db->loadObjectList() );
            $lists['fcountry_id']   = JHTML::_('select.genericlist', $fcountry_id, 'fcountry_id', 'class="inputbox" size="1"','id', 'name' );

            $query = 'SELECT a.* FROM #__simplelisting_layouts as a ORDER BY a.ordering ASC';
            $db->setQuery( $query );
            $flayout_id = array();
            $flayout_id[]   = JHTML::_('select.option', '0', JText::_( 'SELECT_LAYOUT' ), 'id', 'name' );
            $flayout_id = array_merge( $flayout_id, $db->loadObjectList() );
            $lists['flayout_id']   = JHTML::_('select.genericlist', $flayout_id, 'flayout_id', 'class="inputbox" size="1"','id', 'name' );

            $query = 'SELECT a.* FROM #__simplelisting_extras as a ORDER BY a.ordering ASC';
            $db->setQuery( $query );
            $fextra_id = array();
            $fextra_id[]   = JHTML::_('select.option', '0', JText::_( 'SELECT_EXTRAS' ), 'id', 'name' );
            $fextra_id = array_merge( $fextra_id, $db->loadObjectList() );
            $lists['fextra_id']   = JHTML::_('select.genericlist', $fextra_id, 'fextra_id', 'class="inputbox" size="1"','id', 'name' );

            if ($show_price_admin == '0') {
            $forder_id = array(
                JHTML::_('select.option', 'default', JTEXT::_('SELECT_ORDER') ),
                JHTML::_('select.option', 'rdate', JTEXT::_('ORDER_RDATE') ),
                JHTML::_('select.option', 'date', JTEXT::_('ORDER_DATE') ),
                JHTML::_('select.option', 'alpha', JTEXT::_('ORDER_ALPHA') ),
                JHTML::_('select.option', 'ralpha', JTEXT::_('ORDER_RALPHA') )
                );
            } else {
            $forder_id = array(
                JHTML::_('select.option', 'default', JTEXT::_('SELECT_ORDER') ),
                JHTML::_('select.option', 'rdate', JTEXT::_('ORDER_RDATE') ),
                JHTML::_('select.option', 'date', JTEXT::_('ORDER_DATE') ),
                JHTML::_('select.option', 'alpha', JTEXT::_('ORDER_ALPHA') ),
                JHTML::_('select.option', 'ralpha', JTEXT::_('ORDER_RALPHA') ),
                JHTML::_('select.option', 'price', JTEXT::_('ORDER_PRICE') ),
                JHTML::_('select.option', 'rprice', JTEXT::_('ORDER_RPRICE') )
                );
            }
            $lists['forder_id']   = JHTML::_('select.genericlist', $forder_id, 'forder_id', null, 'value', 'text' );

            $this->assignRef('listtitle',           $listtitle);
            $this->assignRef('price_label',         $priceLabel);
            $this->assignRef('category_label',      $categoryLabel);
            $this->assignRef('type_label',          $typeLabel);
            $this->assignRef('address_label',       $addressLabel);
            $this->assignRef('country_label',       $countryLabel);
            $this->assignRef('extras_label',        $extrasLabel);
            $this->assignRef('layout_label',        $layoutLabel);
            $this->assignRef('facilities_label',    $facilitiesLabel);
            $this->assignRef('posted_label',        $postedLabel);
            $this->assignRef('select_theme',        $select_theme);
            $this->assignRef('currency',            $currency);
            $this->assignRef('currencyformat',      $currencyformat);
            $this->assignRef('params',              $params) ;
            $this->assignRef('items',               $items);
            $this->assignRef('lists',               $lists);
            $this->assignRef('pagination',          $pagination);
            $this->assignRef('request_url',         $uri->toString());

            parent::display($tpl);
  }
}
?>
